import {ExportedColumnProps, useTableSearchTextColumnProps} from "./AntdTableUtils";
import {MarketOrderItem} from "../apis/MarketOrderApi";
import ArrayUtils from "@zxy-cn/array-utils";
import {SubGoodsResponse} from "../apis/GoodsApi";
import React from "react"
export function useSubGoodsTableColumnConfiguration<T extends {barcode:string,name:string,subGoods?:SubGoodsResponse}>(){
    let subGoodsNumberSearchColumnProps = useTableSearchTextColumnProps<T>("barcode", {
        placeholder: "子商品编码"
    });

    let subGoodsNameSearchColumnProps = useTableSearchTextColumnProps<T>("name", {
        placeholder: "子商品名称"
    });

    return function (columns:ExportedColumnProps<T>[]){
        ArrayUtils.insertAfter(columns, value => value.dataIndex === "barcode", {
            title: "子商品编号",
            ...subGoodsNumberSearchColumnProps,
            onFilter: (value, record) => {
                return !!record.subGoods?.number.toLowerCase().includes((value as string).toLowerCase())
            } ,
            fixed: true,
            render: (_, record) => {
                return record.subGoods?.number ?? ""
            },
            key:"subGoods.number"
        },)
        ArrayUtils.insertAfter(columns, value => value.dataIndex === "subGoods.number", {
            title: "子商品名称",
            ...subGoodsNameSearchColumnProps,
            onFilter: (value, record) => {
                return !!record.subGoods?.name.toLowerCase().includes((value as string).toLowerCase())
            } ,
            fixed: true,
            render: (_, record) => {
                return record.subGoods?.name ?? ""
            },
            key:"subGoods.name"
        },)
    }
}